
function search() {
  let input = document.getElementById("myInput");
  let filter = input.value.toUpperCase();
  let table = document.getElementById("myTable");
  let tr = table.querySelectorAll("tr");
  // 循环表格每一行，查找匹配项
  for (let i = 0; i < tr.length; i++) {
    let td = tr[i].querySelectorAll("td")[0]; 
    if (td) {
      if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    }
  }
}
let input = document.getElementById("myInput");
input.addEventListener("input", search);

let table = document.getElementById("myTable");
let tr = table.querySelectorAll("tr");
let tr1 = tr[1].innerHTML;
let tr2 = tr[2].innerHTML;
let tr3 = tr[3].innerHTML;
let tr4 = tr[4].innerHTML;

//对公司升序操作
let sheng = document.getElementById("sheng");

sheng.onclick = () => {
  let sum = new Array(0, 0, 0, 0, 0);

  for (let i = 0; i < tr.length; i++) {
    let td = tr[i].querySelectorAll("td")[0];
    if (td) {
      for (let ii = td.innerHTML.toUpperCase().length - 1; ii >= 0; ii--) {
        sum[i] += td.innerHTML.toUpperCase()[1].charCodeAt();
      }
    }
  }
  tr[1].innerHTML = tr1;
  tr[2].innerHTML = tr2;
  tr[3].innerHTML = tr3;
  tr[4].innerHTML = tr4;


  for (let j = 1; j < 5; j++) {
    console.log(sum[j]);
  }
};

//对公司降序操作
let jiang = document.getElementById("jiang");

jiang.onclick = () => {
  let table = document.getElementById("myTable");
  let tr = table.querySelectorAll("tr");
  let sum = new Array(0, 0, 0, 0, 0);
  let some;
  for (let i = 0; i < tr.length; i++) {
    let td = tr[i].querySelectorAll("td")[0];
    if (td) {
      for (let ii = td.innerHTML.toUpperCase().length - 1; ii >= 0; ii--) {
        sum[i] += td.innerHTML.toUpperCase()[1].charCodeAt();
      }
    }
  }

  tr[1].innerHTML = tr4;
  tr[2].innerHTML = tr3;
  tr[3].innerHTML = tr2;
  tr[4].innerHTML = tr1;

  for (let i = 1; i < 5; i++) {
    console.log(sum[i]);
  }
};
